/******************************************************************
 *
 *    Java Lib For Android, Powered By Shenzhen Jiuzhou.
 *
 *    Copyright (c) 2001-2014 Digital Telemedia Co.,Ltd
 *    http://www.d-telemedia.com/
 *
 *    Package:     com.etc.controller.role
 *
 *    Filename:    RoleOperController.java
 *
 *    Description: TODO(用一句话描述该文件做什么)
 *
 *    Copyright:   Copyright (c) 2001-2014
 *
 *    Company:     Digital Telemedia Co.,Ltd
 *
 *    @author:     Administrator
 *
 *    @version:    1.0.0
 *
 *    Create at:   2016年3月25日 下午3:39:27
 *
 *    Revision:
 *
 *    2016年3月25日 下午3:39:27
 *        - first revision
 *
 *****************************************************************/
package com.etc.controller.role;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.etc.common.result.ResultMapper;
import com.etc.common.util.StringUtil;
import com.etc.module.model.ModuleOper;
import com.etc.role.service.IRoleService;
import com.etc.role.vo.RoleVO;

/**
 * @ClassName RoleOperController
 * @Description TODO(这里用一句话描述这个类的作用)
 * @author 张亮
 * @Date 2016年3月25日 下午3:39:27
 * @version 1.0.0
 */
@RestController
@RequestMapping("/roleoper")
public class RoleOperController {
    
    @Autowired
    private IRoleService roleService;
     
    @RequestMapping("/check-nodes")
    @ResponseBody
    public String getAjaxRoleOper(){
        String ss="[{\"text\": \"To Do\", \"cls\": \"folder\",\"expanded\": true,\"children\": [{\"text\": \"Go jogging\",\"leaf\": true,\"checked\": true},{\"text\": \"Take a nap\",\"leaf\": true,\"checked\": false},{\"text\": \"Climb Everest\",\"leaf\": true,\"checked\": false}]}]";
        return ss;
    }
    
    @RequestMapping(value="/save",method=RequestMethod.POST)
    public Map<String,Object> saveRoleOper(HttpServletRequest request){
        String tsrId=request.getParameter("tsrId");
        String tmroIds=request.getParameter("tmroIds");
        if(StringUtil.isNotEmpty(tsrId)&&StringUtil.isNotEmpty(tmroIds)){
            RoleVO roleVO=new RoleVO();
            roleVO.setTsrId(tsrId);
            String[] tmroArray=tmroIds.split(",");
            List<ModuleOper> list=new ArrayList<>();
            for(String tmroId:tmroArray){
                ModuleOper moduleOper=new ModuleOper(Integer.valueOf(tmroId));
                list.add(moduleOper);
            }
            roleService.insertRoleOper(roleVO, list);
            return ResultMapper.convertSuccess();
        }
        return ResultMapper.convertFailure();
        
    }
    
   
}
